package org.jetlinks.community.standalone.entry;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import org.hswebframework.web.api.crud.entity.EntityFactoryHolder;

import java.io.Serializable;

@JsonInclude(Include.NON_NULL)
public class ThingsJsResponseMessage <T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private String message;

    private T data;

    private int code;

    private Boolean success;

    public ThingsJsResponseMessage() {
    }
    public static <T> ThingsJsResponseMessage<T> of(String message, T result, int code, Boolean success) {
        ThingsJsResponseMessage<T> msg = (ThingsJsResponseMessage)EntityFactoryHolder.newInstance(ThingsJsResponseMessage.class, ThingsJsResponseMessage::new);

        msg.setMessage(message);
        msg.setData(result);
        msg.setSuccess(success);
        msg.setCode(code);
        return msg;
    }
    public static <T> ThingsJsResponseMessage<T> ok(T result) {
        return of("success", result, 200, true);
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }
}
